package com.mcxx.common.controller;

import com.alibaba.fastjson.JSON;
import com.mcxx.modules.base.entity.AreaGroupEntity;
import com.mcxx.modules.base.service.read.AreaReadService;
import com.mcxx.modules.dictionary.dto.AreaNewDTO;
import com.mcxx.result.BaseResult;
import com.mcxx.service.DefaultRestService;
import com.yinhai.ta404.component.org.orguser.area.entity.TaAreaPo;
import com.yinhai.ta404.core.validate.annotation.V;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



@Api("行政区划编码控制类")
@RestController
@RequestMapping("area/v2")
public class AreaController extends DefaultRestService {

    private final static Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaReadService areaReadService;


    @GetMapping("listGroupByAreaCode")
    @ApiOperation("根据行政区划编码查询组信息")
    public void listGroupByAreaCode(@V({"notnull"}) String areaCode) {
        logger.info("根据行政区划编码查询组信息，参数：{}", areaCode);
        BaseResult<List<AreaNewDTO>> baseResult = areaReadService.listGroupByAreaCode(areaCode);
        if ("0".equals(baseResult.getCode())) {
            setData(baseResult.getData());
            logger.info("根据行政区划编码查询组信息完成，结果：{}", JSON.toJSONString(baseResult.getData()));
        } else {
            setObjErrors(baseResult.getCode(), baseResult.getMsg());
            logger.error(baseResult.getMsg());
        }
    }

    @GetMapping("queryAreaByCode")
    @ApiOperation("根据行政区划编码查询组信息")
    public void queryAreaByCode(@V({"notnull"}) String areaCode) {
        logger.info("根据行政区划编码查询组信息，参数：{}", areaCode);
        TaAreaPo taAreaPo4 = areaReadService.getAreaByCode(areaCode);
        setData(taAreaPo4);
    }


    @GetMapping("getAgentBanks")
    @ApiOperation("根据地区获取代发银行 信息")
    public void getAgentBanks(){
        logger.info("根据地区获取代发银行信息");
        List<AreaGroupEntity> areaGroupList = areaReadService.getAgentBanks(getCurUserAccount());
        setData(areaGroupList);
        logger.info("根据地区获取代发银行信息,结果是：{}", areaGroupList);
    }
}
